package implicits

import com.github.tototoshi.csv._
import implicits.Implicits._
import org.apache.commons.lang3.StringUtils

import java.io.File
import scala.reflect.ClassTag

/**
 * Created by Administrator on 2019/9/12
 */
trait CSVTool {

  implicit class CSVFile(file: File) {

    def csvLines = {
      val reader = CSVReader.open(file)
      val lines = reader.all()
      reader.close()
      lines
    }
  }

  implicit class CSVLines(lines: List[List[String]]) {

    def toFile(file: File) = {
      val writer = CSVWriter.open(file)
      writer.writeAll(lines)
      writer.close()
      file
    }

    def toTxtFile(file: File) = {
      lines.map(_.mkString("\t")).toFile(file)
    }

  }


}
